package com.baseweb.webadmin.core.model.mapper;

import com.baseweb.webadmin.core.model.Sql.SqlProvider;
import com.baseweb.webadmin.core.model.pojo.ByExampleBudget;
import com.baseweb.webadmin.core.util.RequestPage;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by zx on 2017/8/2.
 */
public interface ByExampleBudgetMapper {

    @Delete({
            "delete from by_example_budget",
            "where id = #{id,jdbcType=INTEGER}"
    })
    Integer deleteByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, example_id, name, level, descn, material,unit,price,money,num, create_time, ",
            "update_time",
            "from by_example_budget",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    ByExampleBudget selectByPrimaryKey(Integer id);

    @Insert({
            "insert into by_example_budget (example_id,num, name, level, ",
            "descn, material,unit,price,money, create_time, ",
            "update_time)",
            "values (#{exampleId,jdbcType=INTEGER},#{num,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
            "#{level,jdbcType=VARCHAR},#{descn,jdbcType=VARCHAR},  ",
            "#{material,jdbcType=VARCHAR},#{unit,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL}, #{money,jdbcType=DECIMAL}, ",
            " #{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
            "#{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    Integer insert(ByExampleBudget record);

    @Update({
            "update by_example_budget",
            "set num = #{num,jdbcType=INTEGER},",
            "name = #{name,jdbcType=VARCHAR},",
            "level = #{level,jdbcType=VARCHAR},",
            "descn = #{descn,jdbcType=VARCHAR},",
            "material = #{material,jdbcType=VARCHAR},",
            "unit = #{unit,jdbcType=VARCHAR},",
            "price = #{price,jdbcType=DECIMAL},",
            "money = #{money,jdbcType=DECIMAL},",
            "create_time = #{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
            "update_time = #{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}",
            "where id = #{id,jdbcType=INTEGER}"
    })
    Integer updateByPrimaryKey(ByExampleBudget record);

    @SelectProvider(type = SqlProvider.class,method = "selectExampleBudgetListByPage")
    @ResultMap("BaseResultMap")
    List<ByExampleBudget> selectExampleBudgetListByPage(@Param("exampleId")Integer exampleId, @Param("page")RequestPage page);

    @SelectProvider(type = SqlProvider.class,method = "countExampleBudgetListByPage")
    Integer countExampleBudgetListByPage(@Param("exampleId")Integer exampleId, @Param("page")RequestPage page);


}
